package com.lxp.uCenterService.controller;


import com.lxp.uCenterService.domain.AdminUser;
import com.lxp.uCenterService.service.AdminUserService;
import com.lxp.utils.MD5;
import com.lxp.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author lxp
 * @since 2022-03-09
 */
@RestController
@RequestMapping("/uCenterService/admin-user")
public class AdminUserController {
    @Autowired
    private AdminUserService service;
    //添加管理员 端口不开放
    @GetMapping("/testAppUser/{username}/{password}")
    public void testAppUser(@PathVariable String username,
                            @PathVariable String password){
        AdminUser user=new AdminUser();
        user.setUsername(username);
        user.setPassword(MD5.encrypt(password));
        service.save(user);
    }

    //登录
    @PostMapping("/login")
    public R Login(@RequestBody AdminUser user){
        String token=service.login(user);
        return R.ok().data("token", token);
    }

}

